/*
 * @lc app=leetcode.cn id=671 lang=javascript
 *
 * [671] 二叉树中第二小的节点
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var findSecondMinimumValue = function(root) {
  let min=root.val
  let result=Infinity
  let dfs=function(node){
      if(!node)return 
      if(node.val==min){
          dfs(node.left)
          dfs(node.right)
      }else if(node.val>min&&node.val<result){
          result=node.val
          return 
      }
  }
  dfs(root)
  return result==Infinity?-1:result
};
// @lc code=end

